//
//  SwiftUIView.swift
//  demo
//
//  Created by Xiaoping Tang on 2023/3/17.
//

import SwiftUI

struct SwiftUIView: View {
    public var vc: UIViewController?
    @ObservedObject public var viewModel: SwiftUIViewModel
    @Environment(\.presentationMode) var presentation
    @Namespace private var namespace
    
    public init(_ viewModel: SwiftUIViewModel) {
        self.viewModel = viewModel
    }
    
    var body: some View {
        VStack(spacing: 0) {
            HStack {
                Image(systemName: "square.and.pencil")
                    .border(Color.gray, width: 1)
                        .contentShape(Rectangle())
                    .onTapGesture {
                        print("test")
                        viewModel.updateId()
                        if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene, let window = scene.keyWindow {
                            
//                            window.makeKeyAndVisible()
                            window.rootViewController?.beginAppearanceTransition(true, animated: true)
                        }
                    }
                Spacer()
                Image(systemName: "xmark.circle")
                    .onTapGesture {
                        print("123")
                    }
            }
            .padding(.horizontal, 16)
            Image(systemName: "text.insert")
                .border(Color.gray, width: 1)
                    .contentShape(Rectangle()) 
                .onTapGesture {
                    print("s")
                    NotificationCenter.default.post(name: .vc2, object: nil, userInfo: nil)
                }
            Spacer()
        }
        .matchedGeometryEffect(id: "swi_ui", in: namespace)
        .border(.green)
//        .ignoresSafeArea(edges: .all)
//        .edgesIgnoringSafeArea(.all)
//        .id(viewModel.id)
        .id(UUID())
//        .padding(.top, 40)
        .background(.white)
        
        
    }
}

//struct SwiftUIView_Previews: PreviewProvider {
//    static var previews: some View {
//        SwiftUIView()
//    }
//}
